// @coding: utf-8
// @author: errorcpp@qq.com

package main

import (
	"net/http"
	"time"

	/* log */
	"github.com/sirupsen/logrus"

	"enic.xlib.xweb/demos/embed_web"
)

func setup_log() {
	// 格式 颜色
	logrus.SetFormatter(&logrus.TextFormatter{
		FullTimestamp:   true,
		TimestampFormat: time.StampMilli, // 设置时间戳格式为毫秒级别
		ForceColors:     true,
	})
	logrus.SetLevel(logrus.TraceLevel)
	logrus.Info("setup log config")
	// 直接接管后log.Fatal会应为调用writer后立即调用exit导致fatal日志无法及时刷新
	// 接管默认标准log
	//logger := logrus.StandardLogger() //logrus.New()
	//log.SetOutput(logger.Writer())
	//log.SetOutput(logger.WriterLevel(logrus.FatalLevel))
	//log.Print("std log was inplaced by logrus !")
	//logrus.Fatal("russsss")  // logrus输出Fatal在exit之前会强制刷新
	//os.Exit(0)
	//log.Fatal("logeeeeeeeee") // 标准库如果只使用SetOutput，最终给logrus的时候丢失level信息无法在exit之前调用刷新
}

func setup_http_service() {
	// Serve the contents over HTTP.
	//http.Handle("/public/", http.StripPrefix("/public/", http.FileServer(statikFS)))
	http.ListenAndServe(":8080", nil)
}

func main() {
	setup_log()
	embed_web.Setup_statik_fs()
	setup_http_service()
}
